package com.sharemarking.wa.platform.mapper;

import com.sharemarking.wa.common.entity.Order;
import com.sharemarking.wa.common.entity.OrderDetails;
import com.sharemarking.wa.platform.dto.orderDriver.DeliveryInfo;
import com.sharemarking.wa.platform.dto.orderDriver.WasteListDto;
import com.sharemarking.wa.platform.dto.orderDriver.OrderListDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author dxy
 */
@Repository
public interface OrderDriverMapper {
    List<OrderListDto> getList(Map map);

    Integer getListTotal(Map map);

    @Select("SELECT a.name AS wasteName,a.waste_Id,a.weight,b.pic FROM wa_order_details a LEFT JOIN wa_org_waste b ON a.waste_id = b.id " +
            "WHERE a.order_id = #{orderId}")
    List<WasteListDto> getWasteList(Integer orderId);

    @Update("UPDATE wa_order_details SET real_weight = #{realWeight},pics = #{pics},update_date = #{updateDate} WHERE order_id = #{orderId} AND waste_id = #{wasteId}")
    void updateOrderDetails(OrderDetails orderDetails);

    @Update("UPDATE wa_order SET state = #{state},actual_transfer_time = #{actualTransferTime} WHERE id = #{id}")
    void updateOrderState(Order order);

    @Select("SELECT c.pic,a.name AS wasteName,a.weight,real_weight,a.pics AS picList FROM wa_order_details a LEFT JOIN wa_order b ON b.id = a.order_id LEFT JOIN wa_org_waste c ON a.waste_id = c.id WHERE b.code = #{code} AND a.waste_id = #{wasteId}  AND b.driver_id = #{driverId}")
    DeliveryInfo getDeliveryInfo(@Param("code") String code, @Param("wasteId") Integer wasteId,@Param("driverId")Integer driverId);

    @Select("SELECT name,real_weight,pics AS picList FROM wa_order_details a LEFT JOIN wa_order b ON b.id = a.order_id WHERE b.code = #{code} AND b.driver_id = #{driverId}")
    List<DeliveryInfo> getDeliveryList(@Param("code") String code,@Param("driverId")Integer driverId);

    @Select("SELECT CONCAT(province,city,area,address) FROM wa_order_address WHERE order_id = #{orderId} AND type = 0")
    String getLoadingAddressByOrderId(Integer orderId);

    @Select("SELECT CONCAT(province,city,area,address) FROM wa_order_address WHERE order_id = #{orderId} AND type = 1")
    String getUnLoadingAddressByOrderId(Integer orderId);
}
